package shanghaielectric_lib.Utils;

import android.util.Log;

/**
 * Created by 45000460 on 2017/12/18.
 */

public class LogUtil {
        private static final String TAG = "";
        //Log开关
        private static final boolean IS_DEBUG = true;

        public static void d(String message) {
            if (IS_DEBUG) Log.d(TAG, createMessage(message));
        }

        public static void e(String message) {
            if (IS_DEBUG) Log.e(TAG, createMessage(message));
        }

        public static void i(String message) {
            if (IS_DEBUG) Log.i(TAG, createMessage(message) );
        }

        public static void v(String message) {
            if (IS_DEBUG) Log.v(TAG, createMessage(message));
        }

        public static void w(String message) {
            if (IS_DEBUG)Log.w(TAG, createMessage(message));
        }

        public static void wtf(String message) {
            if (IS_DEBUG) Log.wtf(TAG, createMessage(message));
        }

        public static void println(String message) {
            if (IS_DEBUG) Log.println(Log.INFO, TAG, message);
        }
    public static void d(String tag,String message) {
        if (IS_DEBUG) Log.d(TAG+tag, createMessage(message));
    }

    public static void e(String tag,String message) {
        if (IS_DEBUG) Log.e(TAG+tag, createMessage(message));
    }

    public static void i(String tag,String message) {
        if (IS_DEBUG) Log.i(TAG+tag, createMessage(message) );
    }

    public static void v(String tag,String message) {
        if (IS_DEBUG) Log.v(TAG+tag, createMessage(message));
    }

    public static void w(String tag,String message) {
        if (IS_DEBUG)Log.w(TAG+tag, createMessage(message));
    }

    public static void wtf(String tag,String message) {
        if (IS_DEBUG) Log.wtf(TAG+tag, createMessage(message));
    }

    public static void println(String tag,String message) {
        if (IS_DEBUG) Log.println(Log.INFO, TAG, message);
    }
        /**
         * 获取有类名与方法名的logString
         * @param rawMessage
         * @return
         */
        private static String createMessage(String rawMessage) {
            /**
             * Throwable().getStackTrace()获取的是程序运行的堆栈信息，也就是程序运行到此处的流程，以及所有方法的信息
             * 这里我们为什么取2呢？0是代表createMessage方法信息，1是代表上一层方法的信息，这里我们
             * 取它是上两层方法的信息
             */
            StackTraceElement[] stackTraceElement = new Throwable().getStackTrace();
            String fullClassName = stackTraceElement[2].getClassName();
            String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
//            return"line:"+stackTraceElement[2].getLineNumber()+" "+ className + "." + stackTraceElement[2].getMethodName() + "(): " + rawMessage;
            return rawMessage;



        }
    }

